package cn.wolfcode.web.controller;


import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.SeckillProductVo;
import cn.wolfcode.redis.SeckillRedisKey;
import cn.wolfcode.service.ISeckillProductService;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;


@RestController
@RequestMapping("/seckillProduct")
@Slf4j
public class SeckillProductController {

    @Autowired
    private ISeckillProductService seckillProductService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @RequestMapping("/queryByTime")
    public Result<List<SeckillProductVo>> queryByTime(Integer time){
        List<SeckillProductVo> collect = seckillProductService.queryByTime(time);
        return Result.success(collect);
    }

    @RequestMapping("/selectTodayListByTime")
    public Result<List<SeckillProductVo>> selectTodayListByTime(@RequestParam("time")Integer time){
        return Result.success(seckillProductService.selectTodayByTime(time)) ;
    }
    @RequestMapping("/find")
    public Result<SeckillProductVo> find(Integer time,Long seckillId){
        return Result.success(seckillProductService.queryByTimeAndSeckillId(time,seckillId)) ;
    }
}
